package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/30 21:04
 **/
public class Day45_14_Offer21_Exchange {
    class Solution {
        public int[] exchange(int[] nums) {
            int left = 0, right = nums.length-1;
            while(left < right){
                while(left < right && nums[left] % 2 == 1){
                    left++;
                }
                while(left < right && nums[right] % 2 == 0){
                    right--;
                }
                if(left < right){
                    int temp = nums[left];
                    nums[left] = nums[right];
                    nums[right] = temp;
                }
            }
            return nums;
        }
    }
}